<template>

    <el-row>
      <el-card shadow="always">{{username}}</el-card>
      <el-card shadow="always">{{tenantName}}</el-card>
    </el-row>
    <el-row>
        <el-col :span="5">
        <el-menu
    router="true"
  >
    <el-sub-menu index="1">
      <template #title>
        <el-icon><location /></el-icon>
        <span>权限管理</span>
      </template>

        <el-menu-item index="1-1" route="/admin">组织架构</el-menu-item>
        <el-menu-item index="1-2" route="/role">角色管理</el-menu-item>

    </el-sub-menu>
    <el-sub-menu index="2">
      
      <template #title>
        <el-icon><document /></el-icon>
        <span>招商</span></template>
      <el-menu-item index="2-2" route="custom">客户管理</el-menu-item>
    </el-sub-menu>
  </el-menu>
    </el-col>
    <el-col :span="19">
        <router-view></router-view>
    </el-col>
    </el-row>
</template>

<script setup>
import {
  Location, Document
} from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue'
import httpRequest from '@/request/index'


const username = ref('')
const tenantName = ref('')
const tenantId = ref('')

onMounted(()=>{
  let userVar = localStorage.getItem('user')
  if (userVar != null) {
    let user = JSON.parse(userVar)
    username.value = user.name
    tenantId.value = user.tenantId
  }

  if (tenantId.value == 0) {
    tenantName.value = '总部'
    return
  }

  httpRequest({
        url: '/auth/tenant',
        method: 'get',
    }).then((res) => {
        if (res.code === 0) {
          for (let i = 0; i < res.data.length; i++){
            if (res.data[i].id == tenantId.value) {
              tenantName.value = res.data[i].name
              break;
            }
          }
        }
    })
})
</script>